// 動態權限的添加
import { constantRoutes, asyncRoutes } from '@/router/index'
const state = {
  // 默認擁有全部靜態權限
  routes: constantRoutes
}
const mutations = {
  // 添加動態權限的方法
  setRoutes(state, newRoutes) {
    state.routes = [...constantRoutes, ...newRoutes]
  }
}
const actions = {
  // 處理過濾動態路由權限並注入 當前角色實際路由列表中實現動態獲取權限
  filtersRoutes(ctx, menus) {
    console.log(menus)
    const newRoutes = asyncRoutes.filter(item => {
      return menus.includes(item.name)
    })
    ctx.commit('setRoutes', newRoutes)
    return newRoutes
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
